package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.EvaluateAddRequest;
import com.macro.mall.model.EvaluateRes;
import com.macro.mall.model.EvaluateResponse;
import com.macro.mall.portal.service.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：尚志豪
 * @Package：com.macro.mall.portal.controller
 * @Project：mall-swarm-B
 * @name：EvaluateController
 * @Date：2024/10/31 11:29
 */
@RequestMapping("/evaluate")
@RestController
public class EvaluateController {

    @Autowired
    private EvaluateService evaluateService;

    /**
     * 评论商品
     */
    @PostMapping("/save")
    public CommonResult save(@RequestBody EvaluateAddRequest evaluateAddRequest) {
        evaluateService.save(evaluateAddRequest);
        return CommonResult.success(null,"评论成功");
    }

    /**
     * 查看评论数
     */
    @PostMapping("/getNum/{productId}")
    public CommonResult getNum(@PathVariable Integer productId){
        int num = evaluateService.getNum(productId);
        return CommonResult.success(num);
    }

    /**
     * 获取商品所有评论
     */
    @PostMapping("/list/{productId}")
    public CommonResult<EvaluateRes> list(@PathVariable Integer productId) {
        EvaluateRes list = evaluateService.list(productId);
        return CommonResult.success(list);
    }

    @PostMapping("/findList/{productId}")
    public CommonResult<EvaluateRes> findList(@PathVariable Integer productId){
        EvaluateRes list = evaluateService.findList(productId);
        return CommonResult.success(list);
    }

    /**
     * 回显
     */
    @PostMapping("/getById/{id}")
    public CommonResult getById(@PathVariable Integer id){
        EvaluateResponse byId = evaluateService.getById(id);
        return CommonResult.success(byId);
    }
}
